import { Bi, Pi } from "@/module-00-codebase/pkg-01-container";
import { BasePage } from "@/module-00-codebase/pkg-03-abstract";
import BaseDetailPage from "./BaseDetailPage";
import BaseListPage from "./BaseListPage";
export class PageInitializer {}
export const initializing = async () => {
  const pd = Bi.propertyDescription;
  const orefTypes = pd.get() as string[];
  for (let i = 0; i < orefTypes.length; i++) {
    const orefType = orefTypes[i];
    const [hasAdd, hasEdt, hasLst] = ["add", "edit", "list"].map(s => pd.getProperties(orefType, s));
    if (hasAdd || hasEdt || hasLst) setRoutePage(orefType, "", BasePage);
    if (hasAdd) setRoutePage(orefType, "add", BaseDetailPage);
    if (hasEdt) setRoutePage(orefType, "edit", BaseDetailPage);
    if (hasLst) setRoutePage(orefType, "list", BaseListPage);
  }
};
export const dependencies = () => ["PropertyDescription", "Utils"];

const setRoutePage = (orefType: string, pageType: string, SuperClass: typeof BasePage) => {
  const route = `/index/rsrc/${Bi.utils.underScore(orefType)}${pageType ? `/${pageType}` : ""}`;
  if (!Pi[route]) {
    const clazz = class C extends SuperClass {
      pageRoutePath = () => route;
    };
    Pi[route] = clazz;
  }
};
